import type { RouteRecordRaw } from 'vue-router'

// 导入页面组件
import LoginPage from '../views/LoginPage.vue'
import DashboardPage from '../views/DashboardPage.vue'
import GoogleCallbackPage from '../views/GoogleCallbackPage.vue'
import GoogleAuthTest from '../views/GoogleAuthTest.vue'
import CustomerManagementPage from '../views/CustomerManagementPage.vue'
import RechargeOrderCreatePage from '../views/RechargeOrderCreatePage.vue'
import RechargeOrderQueryPage from '../views/RechargeOrderQueryPage.vue'
import PayoutOrderCreatePage from '../views/PayoutOrderCreatePage.vue'
import PayoutOrderQueryPage from '../views/PayoutOrderQueryPage.vue'
import AdminSettingsPage from '../views/AdminSettingsPage.vue'
import QuickAmountSettingsPage from '../views/QuickAmountSettingsPage.vue'
import PurchasePriceConfigPage from '../views/PurchasePriceConfigPage.vue'
import PaymentChannelConfigPage from '../views/PaymentChannelConfigPage.vue'
import ProductConfigPage from '../views/ProductConfigPage.vue'
import UserRechargePage from '../views/UserRechargePage.vue'
import NotFoundPage from '../views/NotFoundPage.vue'

// 导入布局组件
import MainLayout from '../components/MainLayout.vue'

// 路由配置
export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Home',
    component: NotFoundPage,
    meta: {
      requiresAuth: false,
      title: '404 - 页面未找到'
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: LoginPage,
    meta: {
      requiresAuth: false,
      title: 'Thailand Recharge System - Login'
    }
  },
  {
    path: '/auth/google/callback',
    name: 'GoogleCallback',
    component: GoogleCallbackPage,
    meta: {
      requiresAuth: false,
      title: 'Google Authentication'
    }
  },
  {
    path: '/google-auth-test',
    name: 'GoogleAuthTest',
    component: GoogleAuthTest,
    meta: {
      requiresAuth: false,
      title: 'Google Authentication Test'
    }
  },
  // 用户充值页面 - 公开路由，无需登录
  {
    path: '/user-recharge/:sessionId',
    name: 'UserRecharge',
    component: UserRechargePage,
    meta: {
      requiresAuth: false,
      title: 'การเติมเงิน'
    }
  },
  // 主应用路由 - 使用新布局
  {
    path: '/',
    component: MainLayout,
    meta: {
      requiresAuth: true
    },
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: DashboardPage,
        meta: {
          title: 'Dashboard'
        }
      },
      {
        path: 'customers',
        name: 'CustomerManagement',
        component: CustomerManagementPage,
        meta: {
          title: 'Customer Management',
          requiresModule: 'user_management'
        }
      },
      {
        path: 'recharge/create',
        name: 'RechargeOrderCreate',
        component: RechargeOrderCreatePage,
        meta: {
          title: 'Create Recharge Order',
          requiresModule: 'recharge_management'
        }
      },
      {
        path: 'recharge/query',
        name: 'RechargeOrderQuery',
        component: RechargeOrderQueryPage,
        meta: {
          title: 'Query Recharge Orders',
          requiresModule: 'recharge_management'
        }
      },
      {
        path: 'payout/create',
        name: 'PayoutOrderCreate',
        component: PayoutOrderCreatePage,
        meta: {
          title: 'Create Payout Order',
          requiresModule: 'payout_management'
        }
      },
      {
        path: 'payout/query',
        name: 'PayoutOrderQuery',
        component: PayoutOrderQueryPage,
        meta: {
          title: 'Query Payout Orders',
          requiresModule: 'payout_management'
        }
      },
      {
        path: 'admin/settings',
        name: 'AdminSettings',
        component: AdminSettingsPage,
        meta: {
          title: 'Admin Settings',
          requiresAdmin: true
        }
      },
      {
        path: 'admin/quick-amounts',
        name: 'QuickAmountSettings',
        component: QuickAmountSettingsPage,
        meta: {
          title: 'Quick Amount Settings',
          requiresAdmin: true
        }
      },
      {
        path: 'admin/purchase-price',
        name: 'PurchasePriceConfig',
        component: PurchasePriceConfigPage,
        meta: {
          title: 'Purchase Price Config',
          requiresAdmin: true
        }
      },
      {
        path: 'admin/channel-config',
        name: 'PaymentChannelConfig',
        component: PaymentChannelConfigPage,
        meta: {
          title: 'Payment Channel Config',
          requiresAdmin: true
        }
      },
      {
        path: 'admin/product-config',
        name: 'ProductConfig',
        component: ProductConfigPage,
        meta: {
          title: 'Product Config',
          requiresAdmin: true
        }
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: NotFoundPage,
    meta: {
      requiresAuth: false,
      title: '404 - 页面未找到'
    }
  }
]

// 路由元信息类型扩展
declare module 'vue-router' {
  interface RouteMeta {
    requiresAuth?: boolean
    requiresAdmin?: boolean
    requiresModule?: string
    title?: string
  }
}
